package com.gqqx.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.gqqx.common.exception.CustomException;
import com.gqqx.common.result.Rt;
import com.gqqx.user.pojo.Weather;
import com.gqqx.user.pojo.vo.WeatherVo;
import com.gqqx.user.service.WeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("qx")
@CrossOrigin
@Api(tags = "气象管理")
public class WeatherController {

    @Autowired
    private WeatherService weatherService;

    @ApiOperation("获取气象编号信息")
    @RequestMapping("stations")
    public Rt findStations(Long id){
        List<Map<Integer,String>> lists = weatherService.findStations();
        return Rt.success(lists);
    }

    @ApiOperation("获取气象数据日期范围")
    @RequestMapping("stations/date")
    public Rt findStationsDate(Long id,String station){
        if (!StringUtils.isEmpty(station)){
            List<String> list = weatherService.findStationsDate(station);
            return Rt.success(null,null,list);
        }else {
            throw new CustomException("参数为空");
        }
    }

    @ApiOperation(value = "获取指定复杂查询条件的气象数据")
    @RequestMapping("query")
    public Rt findWeatherWhole(WeatherVo weatherVo){
        List<List<String>> list = weatherService.findWeatherWhole(weatherVo);
        return Rt.success(list,weatherVo.getStation());
    }

    @ApiOperation(value = "获取任一小时的分钟气象信息")
    @RequestMapping("stat_hour")
    public Rt findHourWeather(String station,String date,String hour,String which) {
        List<String> list = weatherService.findHourWeather(station,date,hour,which);
        return Rt.success(list,station);
    }

    @ApiOperation(value = "获取任一天的小时气象信息")
    @RequestMapping("stat_day")
    public Rt findDayHour(String station,String date,String which){
        List<String> list = weatherService.findDayHour(station,date,which);
        return Rt.success(list,station);
    }

    @ApiOperation(value = "获取任意时间段以天为单位的气象数据")
    @RequestMapping("stat_day_range")
    public Rt findStatDayRange(String station , String start_date,String end_date, String which){
        List<String> list = weatherService.findStatDayRange(station,start_date,end_date,which);
        return Rt.success(list,station);
    }

    @ApiOperation(value = "计算任一时间段内气象数据的协相关矩阵")
    @RequestMapping("correlation")
    public Rt findCorrelation(String station,String start_date,String end_date,String[] correlation){
        List<String> list = weatherService.findCorrelation(station,start_date,end_date,correlation);
        return Rt.success(list,station);
    }

}
